package com.pro.service.imple;

import com.pro.mapper.JsActicleCategroyAddMapper;
import com.pro.mapper.JsCourseRecordMapper;
import com.pro.mapper.JsMicroLogMapper;
import com.pro.pojo.JsCourseRecord;
import com.pro.pojo.JsMicroLog;
import com.pro.pojo.JsMicrocircle;
import com.pro.service.JsActicleCategroyAddService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * ClassName:JsActicleCategroyAddServiceImple
 * Package:com.pro.service.imple
 * Description:
 *
 * @Date:2021/12/1 下午 4:07
 * @Author: WYH
 */
@Service
public class JsActicleCategroyAddServiceImple implements JsActicleCategroyAddService {

    @Autowired(required = false)
    private JsActicleCategroyAddMapper jsActicleCategroyAddMapper;

    @Autowired(required = false)
    private JsMicroLogMapper jsMicroLogMapper;
    
    @Autowired(required = false)
    private JsCourseRecordMapper jsCourseRecordMapper;

    @Override
    public Boolean addMicro(JsMicrocircle jsMicrocircle) {
        jsMicrocircle.setCreateDate(new Date());
        jsMicrocircle.setReleaseDate(new Date());
        jsMicrocircle.setActicleHits(0);
        jsMicrocircle.setActicleLike(0);
        jsMicrocircle.setActicleReviews(0);
        jsMicrocircle.setActicleShare(0);
        jsMicrocircle.setShow(2);
        Boolean aBoolean = jsActicleCategroyAddMapper.addMicro(jsMicrocircle);

        /* 每次添加向日志表中添加数据 */
        long userId = jsMicrocircle.getUserId();
        JsMicroLog jsMicroLog = new JsMicroLog();
        jsMicroLog.setUserId(userId);
        jsMicroLog.setTableName("js_microcircle");
        jsMicroLog.setType("2");
        jsMicroLog.setCreateDate(new Date());
        jsMicroLog.setRemark("添加微圈");
        jsMicroLog.setLogType(3);
        Boolean addMicroLog = jsMicroLogMapper.addMicroLog(jsMicroLog);

        /* 每次添加审核表中添加数据 */
        JsCourseRecord jsCourseRecord = new JsCourseRecord();
        Integer microcircleId = (int)jsMicrocircle.getMicrocircleId();
        jsCourseRecord.setCourseId(microcircleId);
        jsCourseRecord.setApplyDate(new Date());
        long launchId = jsMicrocircle.getUserId();
        String launchIds = Long.toString(launchId);
        jsCourseRecord.setLaunchId(launchIds);
        jsCourseRecord.setResult("2");
        jsCourseRecord.setType(4);
        Boolean addCourseRecord = jsCourseRecordMapper.addJsCourseRecord(jsCourseRecord);

        return aBoolean;
    }
}
